<cfparam name="f" default="docs">
<cfparam name="dir" default="/">
<cfparam name="new_name" default="">
<cfparam name="page_name" default="">

<cfif len(trim(new_name)) GT 0 AND len(trim(page_name)) GT 0>

	<cfset NewFileName = new_name>
    
    <!---Replace all illgegal characters in the link title--->
    <cfset NewFileName = replace(NewFileName, " ", "_", "ALL")>
    <cfset NewFileName = replace(NewFileName, "'", "", "ALL")>
    <cfset NewFileName = replace(NewFileName, '"', '', 'ALL')>
    <cfset NewFileName = replace(NewFileName, "*", "", "ALL")>
    <cfset NewFileName = replace(NewFileName, "&", "", "ALL")>
    <cfset NewFileName = replace(NewFileName, "(", "", "ALL")>
    <cfset NewFileName = replace(NewFileName, ")", "", "ALL")>
    <cfset NewFileName = replace(NewFileName, ";", "", "ALL")>
    <cfset NewFileName = replace(NewFileName, ":", "", "ALL")>
    <cfset NewFileName = replace(NewFileName, "!", "", "ALL")>
    <cfset NewFileName = replacenocase(NewFileName, ".htm", "", "ALL")>
    <cfset NewFileName = replacenocase(NewFileName, ".php", "", "ALL")>
    <cfset NewFileName = replacenocase(NewFileName, ".asp", "", "ALL")>
    <cfset NewFileName = replacenocase(NewFileName, ".js", "", "ALL")>            
    <cfset NewFileName = replacenocase(NewFileName, ".txt", "", "ALL")>
    <cfset NewFileName = replacenocase(NewFileName, ".cfm", "", "ALL")>
    <cfset NewFileName = replacenocase(NewFileName, ".html", "", "ALL")>
    <cfset NewFileName = replacenocase(NewFileName, ".", "", "ALL")>    
    <cfset NewFileName = replacenocase(NewFileName, "@", "", "ALL")>
    <cfset NewFileWithExt = NewFileName & '.cfm'>
    
    <cfif fileexists('#request.basepath##f##dir##NewFileWithExt#')>
        <!---duplicate so display error message--->
        <cfset waserror = 1>
        <div id="messages_error">A page by that name already exists.  Please choose another name.</div>
    <cfelse>
        <!---page not found so write new page and redirect--->
        <cffile action="rename" source="#request.basepath##f##dir##page_name#" destination="#request.basepath##f##dir##NewFileWithExt#">
        <cfoutput><div id="messages">#page_name# was renamed to #new_name#</div></cfoutput>
    </cfif>

<cfelse>
        <div id="messages_error">You must give this page a name.</div>
</cfif>

<!---redirect--->    
<p>
<cfoutput>
Your browser will redirect in a few seconds...<br />
<a href = "index.cfm?c=pages&a=default&f=#f#&dir=#dir#">Click here if it does not redirect in 5 seconds</a>
</p>
<script language="javascript">
pageurl = 'index.cfm?c=pages&a=default&f=#f#&dir=#dir#';
setTimeout('delayer(pageurl)', 3000);
</script>
</cfoutput>